package pro.lingwu.station.service.impl;

import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;
import pro.lingwu.station.dao.BusMapper;
import pro.lingwu.station.dto.PagesResult;
import pro.lingwu.station.dto.db.Bus;
import pro.lingwu.station.service.BusService;

import java.util.List;

/**
 * @author @lingwu
 * @date created in 11/19/2021
 */
@Service
public class BusServiceImpl implements BusService {

    private final BusMapper mapper;

    public BusServiceImpl(BusMapper mapper) {
        this.mapper = mapper;
    }

    @Override
    public void addBus(Bus bus) {
        mapper.addBus(bus);
    }

    @Override
    public void rmBus(String busNum) {
        mapper.rmBus(busNum);
    }

    @Override
    public PagesResult<Bus> getAllBus(int start, int size) {
        if (size>-1){
            PageHelper.startPage(start, size);
        }
        var res = new PagesResult<Bus>();
        res.setResult( mapper.getAllBuses());
        res.setTotal(mapper.getTotal());
        return res;
    }

    @Override
    public void updateBus(Bus bus, String oldBusNum) {
        mapper.updateBus(bus, oldBusNum);
    }

    @Override
    public Bus getBusBy(String busNum) {
        return mapper.findBusBy(busNum);
    }
}
